<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.gxgyl.com All rights reserved.

// +----------------------------------------------------------------------
// | Author: Liuyu
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\api\model\shiyao;

use app\common\model\shiyao\PayOpenImage as PayOpenImageModel;
use cores\exception\BaseException;
/**
 * 公开凭证模型
 * Class GoodsImage
 * @package app\store\model
 */
class PayOpenImage extends PayOpenImageModel
{
    /**
     * 批量写入商品图片记录
     * @param int $goodsId
     * @param array $imageIds
     * @return array|false
     */
    public static function increased(int $payId, array $imageIds)
    {
        $dataset = [];
        foreach ($imageIds as $imageId) {
            $dataset[] = [
                'image_id' => $imageId,
                'pay_log_id' => $payId,
                'store_id' => self::$storeId
            ];
        }
        return (new static)->addAll($dataset);
    }

    /**
     * 更新关系记录
     * @param int $goodsId
     * @param array $imageIds 新的图片集
     * @return array|false
     */
    public static function updates(int $payId, array $imageIds)
    {
        // 删除所有的sku记录
        static::deleteAll(['pay_log_id' => $payId]);
        // 批量写入商品图片记录
        return static::increased($payId, $imageIds);
    }
}
